import { createStore, applyMiddleware } from 'redux'  
// applyMiddleware  应用中间件
// redux-logger   记录redux中的数据
// import logger from 'redux-logger'
import thunk from 'redux-thunk'
// redux-thunk  修改dispatch函数    可以在dispatch函数中传递一个函数
import axios from 'axios'

// redux-thunk 
// redux-saga

// reducer  不能处理异步操作
// redux中处理异步  使用中间件
let reducer = (state, { type, res }) => {
    let NewState = { ...state }
    switch(type) {
        case "ADD":
            // axios.get('/getNum').then(res => {
            //     state.count += res.data
            // })
            // console.log(state.count)
            NewState.count += res
            return NewState
        default:
            return state
    }
}

let initState = {
    count: 100
}

let store = createStore(reducer, initState, applyMiddleware(thunk))

window.store = store

// redux
// react-redux

export default store